using UnityEngine;
using System;
using System.Xml;
using System.Xml.Serialization; 

public class GPObject : TObject
{
	
	[XmlAttribute("id")]
	public int Id{ get; set; }
	
	[XmlAttribute("type")]
	public ObjectType Type{ get; set; }
	
	[XmlAttribute("fixed")]
	public bool IsFixed{ get; set; }
	
	[XmlElement("posX")]
	public float PosX{ get; set; }
	
	[XmlElement("posY")]
	public float PosY{ get; set; }
	
	[XmlElement("rotation")]
	public float Rotation{ get; set; }
	
	[XmlElement("color")]
	public Color ObjColor{ get; set; }
	
	
	public GPObject(){
			
	}
	
	public GPObject (int id, ObjectType type, float posX, float posY, float rotation, Color objColor, bool isFixed = false)
	{
		this.Id = id;
		this.Type = type;
		this.IsFixed = isFixed;
		this.PosX = posX;
		this.PosY = posY;
		this.Rotation = rotation;
		this.ObjColor = objColor;
	}

	
	public GPObject(GameObject go){
		Id = 0;
		
		PosX = go.transform.position.x;
		PosY = go.transform.position.y;
		Rotation = go.transform.eulerAngles.z;
		
		ObjectType t = (ObjectType)Enum.Parse(typeof(ObjectType), go.tag, true);
		Type = t;
		
		ObjColor = Color.white;
		IsFixed = false;
		if(go.GetComponent<LightRayHandler>() != null){
			Id = go.GetComponent<LightRayHandler>().Id;
			ObjColor = go.GetComponent<LightRayHandler>().currentColor;
			IsFixed = go.GetComponent<LightRayHandler>().isFixed;
		}
	}
	
	public Vector3 Position{
		get {
			return new Vector3(PosX,PosY,0);
		}
	}
	
	public override string ToString ()
	{
		return string.Format ("[GPObject: ID={5} Type={0}, IsFixed={1}, Position={2}, Rotation={3}, ObjColor={4}]", Type, IsFixed, Position, Rotation, ObjColor, Id);
	}
	
}

